package org.joyflow.core.meta;

public class ValueMetaBase implements ValueMetaInterface {
    protected String name;
    protected int type;
    protected int length;
    protected int precision;

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public int getType() {
        return type;
    }

    @Override
    public int getLength() {
        return length;
    }

    @Override
    public void setLength(int length) {
        this.length = length;
    }

    @Override
    public int getPrecision() {
        if (isInteger() || isBinary()) {
            return 0;
        }
        if (isString() || isBoolean()) {
            return -1;
        }
        return precision;
    }

    @Override
    public void setPrecision(int precision) {
        this.precision = precision;
    }

    @Override
    public boolean isInteger() {
        return type == TYPE_INTEGER;
    }

    @Override
    public boolean isBinary() {
        return type == TYPE_BINARY;
    }

    @Override
    public boolean isNumeric() {
        return isInteger() || isNumber() || isBigNumber();
    }

    @Override
    public boolean isNumber() {
        return type == TYPE_NUMBER;
    }

    @Override
    public boolean isBoolean() {
        return type == TYPE_BOOLEAN;
    }

    @Override
    public boolean isString() {
        return type == TYPE_STRING;
    }

    @Override
    public boolean isBigNumber() {
        return type == TYPE_BIGNUMBER;
    }

    @Override
    public boolean isDate() {
        return type == TYPE_DATE || type == TYPE_TIMESTAMP;
    }
}
